<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: snow_header"></head>
<body class="gray-bg">
    <div class="container-div">
		<div class="btn-group hidden-xs" id="toolbar" role="group">
			<a class="btn btn-outline btn-success btn-rounded" onclick="configGroupTable.operateAdd()" shiro:hasPermission="module:group:add">
				<i class="fa fa-plus"></i> 新增
			</a>
			<a class="btn btn-outline btn-danger btn-rounded" onclick="configGroupTable.releaseAll()" shiro:hasPermission="module:group:release">
				<i class="fa  fa-cloud-upload"></i> 发布
			</a>
		</div>
			
		<div class="col-sm-12 select-table table-striped">
			<table id="config_group" data-mobile-responsive="true"  style="white-space:nowrap"></table>
		</div>
    </div>
    <div th:include="include :: snow_footer"></div>
    <script th:inline="javascript">
        // configGroupTable.releaseAll=function () {
        //     // 批量删除信息
        //         var rows = $.common.isEmpty(this._option.id) ? this.selectFirstColumns() : this.selectColumns(this._option.id);
        //         if (rows.length == 0) {
        //             $.modal.alertWarning("请至少选择一条记录");
        //             return;
        //         }
        //         $.modal.confirm("确认要发布选中的" + rows.length + "条数据吗?", function() {
        //             var url = prefix + "/release";
        //             var data = { "ids": rows.join() };
        //             $.operate.submit(url, "post", "json", data);
        //         });
        // }


        var editFlag = [[${@permission.hasPermi('module:group:edit')}]];
        var listFlag = [[${@permission.hasPermi('module:group:list')}]];
        var removeFlag = [[${@permission.hasPermi('module:group:remove')}]];
        var prefix = ctx + "module/group";
        var datas = [[${@dict.getType('sys_yes_no')}]];

        var configGroupTable=$.snowBootstrap.init("config_group");
        $(function() {
            //扩展方法
            $.extend(configGroupTable,{
                releaseAll: function () {
                    // 批量删除信息
                    var rows = $.common.isEmpty(this._option.id) ? this.selectFirstColumns() : this.selectColumns(this._option.id);
                    if (rows.length == 0) {
                        $.modal.alertWarning("请至少选择一条记录");
                        return;
                    }
                    $.modal.confirm("确认要发布选中的" + rows.length + "条数据吗?", function () {
                        var url = prefix + "/release";
                        var data = {"ids": rows.join()};
                        $.operate.submit(url, "post", "json", data);
                    });
                }
            });
            console.log(configGroupTable);

            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                copyUrl: prefix + "/copy/{id}",
                removeUrl: prefix + "/remove",
                modalName: "配置组",
                columns: [{
		            checkbox: true
		        },
				{
					field : 'configGroupId',
					title : '配置组ID'
				},
				{
					field : 'groupName',
					title : '组名称'
				},
				{
					field : 'description',
					title : '描述'
				},
				{
					field : 'groupType',
					title : '配置组类型'
				},
                {
                    field : 'propertyPrefix',
                    title : '配置前缀'
                },
                {
                    field: 'pushUpdate',
                    title: '推送更新',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var valueTemp='N';
                        if(value){
                            valueTemp='Y';
                        }
                        console.log(value,valueTemp,datas,$.table.selectDictLabel(datas, valueTemp));
                        return $.table.selectDictLabel(datas, valueTemp);
                    }
                },
				{
					field : 'remark',
					title : '备注'
				},
				{
					field : 'status',
					title : '状态'
				},
				{
					field : 'modify',
					title : '是否修改'
				},
				{
					field : 'maxVersion',
					title : '最高版本号'
				},
				{
					field : 'currentVersion',
					title : '当前版本号'
				},
				{
					field : 'createBy',
					title : '创建者'
				},
				{
					field : 'createTime',
					title : '创建时间'
				},
				{
					field : 'updateBy',
					title : '更新者'
				},
				{
					field : 'updateTime',
					title : '更新时间'
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="configGroupTable.operateEdit(\'' + row.configGroupId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-warning btn-xs ' + listFlag + '" href="#" onclick="configGroupTable.operateCopy(\'' + row.configGroupId + '\',\''+row.description+'\')"><i class="fa fa-copy"></i>复制</a> ');
                        actions.push('<a class="btn btn-info btn-xs ' + listFlag + '" href="#" onclick="detail(\'' + row.configGroupId + '\',\''+row.description+'\')"><i class="fa fa-list-ul"></i>列表</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="remove(\'' + row.configGroupId + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }]
            };

            console.log(configGroupTable);
            configGroupTable.tableInit(options);
            // $.table.init(options,"config_group");
        });

        /*字典列表-详细*/
        function detail(configGroupId,titleName) {
            var url = prefix + '/detail/' + configGroupId;
            createMenuItem(url, "配置属性["+titleName+"]");
        }

        function remove(id) {
            var hasChilds=true;
            $.ajax({
                async:false,
                type : 'post',
                url: prefix + "/hasChilds?uniqueId=" + id,
                success : function(result) {
                    console.log("result=",result);
                    if (!result) {
                        hasChilds=false;
                    }
                }
            });
            if(hasChilds){
                $.modal.alertError("该条记录包含关联子表,不允许删除");
                return;
            }

            $.modal.confirm("确定删除该条[" + configGroupTable._option.modalName + "]信息吗？", function() {
                $.ajax({
                    type : 'post',
                    url: prefix + "/remove?ids=" + id,
                    success : function(result) {
                        if (result.code == web_status.SUCCESS) {
                            $.modal.msgSuccess(result.msg);
                            configGroupTable.refresh();
                        } else {
                            $.modal.msgError(result.msg);
                        }
                    }
                });
            });
        }
    </script>
</body>
</html>